# Dickstein, Ho, and Mark (2023)
# This script runs counterfactuals using a fixed markup in a loop.

# Preliminaries
setwd("../../../../library")
source("PreliminariesCode.R")

# Where is the counterfactual folder? 
counterfactual_folder <- paste0(project_folder, "/analysis/counterfactuals")

# Which demand specification do you want to use?
spectouse <- "lowrisk_simplemh_censor0.2"

# Create an output folder
dir.create(paste0(counterfactual_folder, "/specs/", spectouse, "/output"), recursive = T)

# What markups to use? 
mrkup_vec <- c(0, .1, .2, .25)
  
# What version do you want to save the build data for? 
save_build_data_vec <- c(T, F, F, T)

for(i in seq_along(mrkup_vec)){
  ls_beforesource <- ls()
  mrkup <- mrkup_vec[i]
  save_build_data <- save_build_data_vec[i]
  results_file <- paste0(counterfactual_folder, "/specs/", spectouse, "/output/results_", round(100 * mrkup, 0), "pctmarkup.txt")
  dirtosave <- paste0(project_folder, "/analysis/tablesandfigures/release/counterfactuals/", spectouse, "/fixedmarkup", round(100 * mrkup, 0))
  source(paste0(counterfactual_folder, "/specs/", spectouse, "/DA03cRunCounterfactuals1table.R"))
  rm(list = setdiff(ls(), ls_beforesource))
}
